package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.tradeapplicationconfirmletter.LindiTradeApplicationConfirmLetterQueryVO;
import com.minimalist.common.entity.lindi.vo.tradeapplicationconfirmletter.LindiTradeApplicationConfirmLetterVO;
import com.minimalist.common.feign.client.lindi.LindiTradeApplicationConfirmLetterFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 林地指标交易平台_交易申请确认函Feign客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 * @since 2024-12-19
 */
@Component
public class LindiTradeApplicationConfirmLetterFeignClientFallbackFactory extends BaseFallbackFactory<LindiTradeApplicationConfirmLetterFeignClient> {
    private static final Logger log = LoggerFactory.getLogger(LindiTradeApplicationConfirmLetterFeignClientFallbackFactory.class);


    @Override
    public LindiTradeApplicationConfirmLetterFeignClient create(Throwable cause) {
        return new LindiTradeApplicationConfirmLetterFeignClient() {

            @Override
            public R<?> addTradeApplicationConfirmLetter(LindiTradeApplicationConfirmLetterVO tradeApplicationConfirmLetterVO) {
                logServiceUnavailable("添加交易申请确认函", tradeApplicationConfirmLetterVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "添加交易申请确认函失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteTradeApplicationConfirmLetterByConfirmLetterId(Long confirmLetterId) {
                logServiceUnavailable("删除交易申请确认函", confirmLetterId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除交易申请确认函失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateTradeApplicationConfirmLetterByConfirmLetterId(LindiTradeApplicationConfirmLetterVO tradeApplicationConfirmLetterVO) {
                logServiceUnavailable("修改交易申请确认函", tradeApplicationConfirmLetterVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "修改交易申请确认函失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiTradeApplicationConfirmLetterVO>> getPageTradeApplicationConfirmLetterList(LindiTradeApplicationConfirmLetterQueryVO queryVO) {
                logServiceUnavailable("分页查询交易申请确认函列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "分页查询交易申请确认函列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiTradeApplicationConfirmLetterVO> getTradeApplicationConfirmLetterByConfirmLetterId(Long confirmLetterId) {
                logServiceUnavailable("获取交易申请确认函详情", confirmLetterId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "获取交易申请确认函详情失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiTradeApplicationConfirmLetterVO> getTradeApplicationConfirmLetterByTradeApplicationId(Long tradeApplicationId) {
                logServiceUnavailable("根据交易申请ID查询确认函", tradeApplicationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "根据交易申请ID查询确认函失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<List<LindiTradeApplicationConfirmLetterVO>> getTradeApplicationConfirmLetterListByTradeApplicationId(Long tradeApplicationId) {
                logServiceUnavailable("根据交易申请ID查询确认函列表", tradeApplicationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "根据交易申请ID查询确认函列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiTradeApplicationConfirmLetterVO> generateConfirmLetter(Long tradeApplicationId, String confirmLetterType, Long createId, Long tenantId) {
                logServiceUnavailable("生成确认函", "tradeApplicationId: "
                        + tradeApplicationId + ", confirmLetterType: "
                        + confirmLetterType, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "生成确认函失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteTradeApplicationConfirmLetterFileByFileId(Long fileId) {
                logServiceUnavailable("删除交易申请确认函文件", fileId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除交易申请确认函文件失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}
